﻿using Data;
using Logic;
using Services.Progress;
using UnityEngine;

namespace Infrastructure.States
{
    public class GameLoopState : IState
    {
        private readonly LoadingCurtain _loadingCurtain;
        private readonly IProgressService _progressService;
        private GameSceneData _data;

        public GameLoopState(LoadingCurtain loadingCurtain, IProgressService progressService)
        {
            _loadingCurtain = loadingCurtain;
            _progressService = progressService;
        }

        public void Enter() =>
            _data = _progressService.Progress.GameSceneData;

        public void Exit()
        {
            _loadingCurtain.Show();
            Object.Destroy(_data.Exit);
            _data.Exit = null;
            Object.Destroy(_data.Hero);
            Object.Destroy(_data.Hud);
            Utils.Cleanup(_data.Obstacles);
            Utils.Cleanup(_data.FloorElements);
            Utils.Cleanup(_data.LootPieces);
            Utils.Cleanup(_data.Bullets);
        }
    }
}